import ResLoader from "../../cfw/res/ResLoader";
import AudioManager from "../../cfw/audio/AudioManager";
import ResHelper from "../../engine/ResHelper";
import { isNull } from "../tools/Define";
export default class Module {

    private loader: ResLoader;

    protected audio: AudioManager;

    protected projectName: string = ''

    protected config: any;

    constructor(projectName: string, config: any, hasSubPackage: boolean = true) {
        this.projectName = projectName;
        this.config = config;
        //有名称的模块，需要在适当的时候加载bundle 并设置。
        if (!config.isBundle) {//name != '' 的 说明是自定义的bundle。
            this.setLoader(new ResLoader(new ResHelper(cc.resources, hasSubPackage ? "" : config.bundleName)))
        }

    }

    setAudio() {
        if (this.loader) {
            this.audio = new AudioManager(this.projectName, this.loader)
        }
    }

    hasLoader() {
        return !isNull(this.loader)
    }

    setLoader(loader: ResLoader) {
        this.loader = loader
    }

    setLoaderByBundle(bundle: cc.AssetManager.Bundle) {
        this.setLoader(new ResLoader(new ResHelper(bundle)))
        this.setAudio()
    }

    isBundle() {
        return this.config.isBundle;
    }

    getName() {
        return this.config.bundleName
    }

    getLoader() {
        return this.loader;
    }

    getAudio() {
        return this.audio;
    }
}